package jjn.round2;

import java.util.Arrays;

/**
 * @author Jiang Jining
 * @since 2023-06-07 18:48
 */
public class LeetCode2611_MiceAndCheese {
    public int miceAndCheese(int[] reward1, int[] reward2, int k) {
        int[] diff = new int[reward1.length];
        int res = 0;
        for (int i = 0; i < reward2.length; i++) {
            res += reward2[i];
            diff[i] = reward1[i] - reward2[i];
        }
        Arrays.sort(diff);
        for (int i = 1; i <= k; i++) {
            res += diff[reward2.length - i];
        }
        return res;
    }
}
